package wang.yangziqing.app_kotlin.base

import android.app.Activity
import android.os.Bundle
import android.os.PersistableBundle
import android.support.v7.app.AppCompatActivity
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.debug
import org.jetbrains.anko.error
import org.jetbrains.anko.toast
import org.jetbrains.anko.startActivity
import wang.yangziqing.app_kotlin.ui.activity.MainActivity

/**
 * Created by Administrator on 2017/11/29.
 * 所有Activity的基类
 */
abstract class BaseActivity : AppCompatActivity(),AnkoLogger {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //设置布局
        setContentView(getLayoutId())
        //初始化数据
        initData()
        //监听
        initListener()

    }

    /**
     * 获取布局的id
     */
    abstract fun getLayoutId(): Int

    /**
     * 初始化数据
     */
   open protected fun initData() {

    }

    /**
     * adapter listener
     */
    open protected fun initListener() {

    }

      protected fun myToast(msg: String) {

        runOnUiThread { toast(msg) }
    }

      protected fun myToast(msg: Int) {

        runOnUiThread { toast(msg) }
    }
    /**
     *  开启一个新的界面 并且关闭自己
     *  reified:限制T的类型 需要内联关键字 inline
     */
inline fun <reified T: BaseActivity> startActivityAndFinishMyself(){
        startActivity<T>()
        finish()//关闭当前的界面
    }
}